package com.zq.it.tool;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class ExamUtil {
	public static double CompareJSON(String key, String userkey) {
		JSONArray array_key = JSONArray.fromObject(key);
		JSONArray array_userkey = JSONArray.fromObject(userkey);
		if ((array_key == null) || (array_userkey == null)
				|| (array_key.size() < 2) || (array_userkey.size() < 1)) {
			return 0.0D;
		}
		if (key.contains("{\"QCOMPLEX\":\"YES\"}")) {
			String userkey_bak = key;
			double total = 0.0D;
			for (int i = 0; i < array_userkey.size(); i++) {
				JSONObject jo = array_userkey.getJSONObject(i);
				String VAL = (String) jo.get("VAL");
				String user_this_key = "\"VAL\":\"" + VAL + "\"";
				if (userkey_bak.contains(user_this_key)) {
					userkey_bak = userkey_bak.replaceAll(user_this_key, "");
					total += 1.0D;
				}
			}
			return total / (array_key.size() - 1);
		}
		double total = 0.0D;
		try {
			for (int i = 0; i < array_userkey.size(); i++) {
				JSONObject jo = array_userkey.getJSONObject(i);
				String ID = jo.get("ID").toString();
				String VAL = jo.get("VAL").toString();
				for (int j = 0; j < array_key.size(); j++) {
					JSONObject jokey = array_key.getJSONObject(j);
					String KEYID = (String) jokey.get("ID");
					String KEYVAL = (String) jokey.get("VAL");
					if ((ID.equals(KEYID)) && (VAL.equals(KEYVAL))) {
						total += 1.0D;
					}
				}
			}
			return total / (array_key.size() - 1);
		} catch (Exception localException) {
			localException.printStackTrace();
		}
		return 0.0D;
	}
}
